/**
 * 
 */
package com.antilia.infomaresme.pages.images;

import org.apache.wicket.ajax.AjaxEventBehavior;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.image.NonCachingImage;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.request.resource.DynamicImageResource;

import com.antilia.infomaresme.InfomaresmeApplication;
import com.antilia.infomaresme.data.services.IImageService;
import com.antilia.infomaresme.data.services.ImageDetail;

/**
 * @author Ernesto
 *
 */
public class ImagePanel extends Panel {

	private static final long serialVersionUID = 1L;

	private NonCachingImage cachingImage;
	/**
	 * @param id
	 * @param model
	 */
	public ImagePanel(String id, final ImageDetail detail, final int width, final int height) {
		super(id);
		setRenderBodyOnly(true);
		cachingImage = new NonCachingImage("image", new DynamicImageResource() {
			
			private static final long serialVersionUID = 1L;


			@Override
			protected byte[] getImageData(Attributes attributes) {
				return getImagesService().resizeImage(detail, width, height).getBytes();
			}
		});
		cachingImage.add(new AjaxEventBehavior("onclick") {
		
			private static final long serialVersionUID = 1L;

			@Override
			protected void onEvent(AjaxRequestTarget target) {
				ImagePanel.this.onEvent(target);
			}
		});		
		cachingImage.setOutputMarkupId(true);
		add(cachingImage);
	}

	public IImageService getImagesService() {
		return InfomaresmeApplication.getQAApplication().getImageService();
	}

	protected void onEvent(AjaxRequestTarget target) {
		
	}

	public NonCachingImage getCachingImage() {
		return cachingImage;
	}
	


}
